package org.example.emp.config;

import org.example.emp.exception.SqlDataException;
import org.example.emp.pojo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * 异常捕获器
 */
@ResponseBody
@ControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {

    @ExceptionHandler(SqlDataException.class)
    public Result<String> exceptionHandler(SQLIntegrityConstraintViolationException ex){
        return new Result(100 , ex.getMessage());
    }


}
